package com.util;

import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;


/**
 * @author mornd
 * @date 2020/10/21 - 20:30
 */
public class BCryptPasswordEncoderUtils {
    private static BCryptPasswordEncoder bCryptPasswordEncoder;

    static {
        bCryptPasswordEncoder = new BCryptPasswordEncoder();
    }

    /**
     * 加密
     *
     * @param password 要加密的密码
     * @return
     */
    public static String encode(String password) {
        return bCryptPasswordEncoder.encode(password);
    }

    /**
     * 解密
     *
     * @param rawPassword     未加密的密码
     * @param encodedPassword 已加密的密码
     * @return
     */
    public static Boolean decode(String rawPassword, String encodedPassword) {
        return bCryptPasswordEncoder.matches(rawPassword, encodedPassword);
    }

    /**
     * 打印加密的密码
     * @param args
     */
    /*public static void main(String[] args) {
        System.out.println(bCryptPasswordEncoder.encode("000"));
    }*/

}
